<template>
  <div class="musicList">
    <div class="top">
      <div class="title">推荐歌单</div>
      <div class="more">查看更多</div>
    </div>
  </div>
  <div class="mlist">
    <van-swipe class="my-swipe" :loop="false" :show-indicators="false" :touchable="true" :width="105" >
      <!-- 每一个推荐歌单 -->
        <van-swipe-item v-for="(item,index) in songList" :key="index">
          <!-- 点进歌单，并传送当前歌单的 id -->
          <router-link :to="{path: '/listview', query: {id: item.id}}" style="color: #fff;">
            <div class="song-hog">
              <span class="num">▷{{formatNumber(item.playCount)}}</span>
            </div>
            <img :src="item.picUrl" alt=""> 
            <div>
              <span class="item-title">{{item.name}}</span>
            </div>
          </router-link>
      </van-swipe-item>
    </van-swipe>
  </div>
</template>

<script setup>
import { nextTick, onMounted, reactive, ref } from "vue";
import { getRecommendedSongs } from '@/network/home.js'
import { formatNumber } from '@/util/formatNumber.js'
import { useStore } from 'vuex'

// 推荐歌单数据列表
const songList = reactive([])
const store = useStore()


//TODO 获取推荐歌单数据
const getSongList = async ()=> {
  const {data: res} = await getRecommendedSongs()
  songList.push(...res.result)
}

onMounted(() => {
  getSongList()
})

</script>

<style lang="less" scoped>
.musicList {
  margin-top: 0.2rem;
  width: 7.5rem;
  padding: 0 0.2rem;
  .top {
    height: 0.5rem;
    display: flex;
    justify-content: space-between;
    .title {
      font-size: 0.35rem;
      font-weight: 900;
    }
    .more {
      border: 1px solid #ccc;
      border-radius: 0.3rem;
      font-size: 0.16rem;
      height: 0.5rem;
      width: 1.2rem;
      text-align: center;
      line-height: 0.5rem;
    }
  }
}
.my-swipe {
  margin-top: 0.3rem;
}
.van-swipe-item {
  margin-left: 10px;
  border-radius: 10px;
  color: #fff;
  text-align: center;
  // background-color: #ccc;
  img {
    border-radius: 10px;
    width: 100%;
    height: 100%;
  }
  .item-title {
    color: black;
    font-size: 12px;
    text-align: left;
    // 文字两行显示
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .song-hog {
    position: absolute;   
    top: 5px; 
    right: 3px;
    height: 15px;
    // background-color: rgba(254,219,207,0.2);
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    text-align: center;
    line-height: 15px;
  }
  .san {
    width: 10px;
    z-index: 1;
    padding-left: 1px;

  }
  .num {
    height: 100%;
    color: #fff;
    font-size: 0.1rem;
    padding: 5px;
  }
  
}

</style>